﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrderApp2
{
    public class OrderItem
    {
        //商品名称
        public string itemName;
        //商品单价
        public  double itemPrice;
        //商品数量
        public  int itemNum;
        //单个商品总价
        public  double item_priceInTotal
        {
            get => itemPrice * itemNum;
        }

        public OrderItem(string item_name,double item_price,int item_num)
        {
            this.itemName = item_name;
            this.itemPrice = item_price;
            this.itemNum = item_num;

        }
        //打印订单明细
        public override string ToString()
        {
            return
                  $"{itemName.PadRight(15)}" 
                  + $"{itemPrice.ToString().PadRight(10)}" 
                  + $"{itemNum.ToString().PadRight(10)}" 
                  + $"{item_priceInTotal.ToString().PadRight(8)}";

        }

        //重写Equals
        public override bool Equals(object obj)
        {
            OrderItem orderItem = obj as OrderItem;
            if (orderItem == null)
                return false;
            else
            {
                return orderItem.itemName == itemName;
            }
        }
    }
}
